<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <?php include_http_metas() ?>
        <?php include_metas() ?>
        <?php include_title() ?>
        <link rel="shortcut icon" href="/favicon.ico" />
        <?php include_stylesheets() ?>
        <?php include_javascripts() ?>
        <script type="text/javascript">
        
            jQuery(document).ready(function(){
                index = jQuery('[class*=sf_admin_form_field_condition]').length;
                add_button();
                add_delete_link();
            });
		
            function add_button(){
                if(jQuery('.sf_admin_form_field_condition_1').length){
                    index++;
                    jQuery('.sf_admin_form_row:last').append('<button onclick="return add_condition(this)"><?php echo __('Add another condition') ?></button>');
                }
                jQuery('._delete_:last').click(function(){
                    jQuery(this).parent().parent().remove();
                });
            }
		
            function add_delete_link(){
                jQuery('div[class*=sf_admin_form_field_condition] > div > label').append('<div class="_delete_"></div>');
                jQuery('._delete_').each(function(k,v){
                    jQuery(v).attr('db_id',jQuery(v).parent().parent().find('tr').find('input[type=hidden]:eq(0)').val());
                });
			
                jQuery('._delete_').click(function(){
                    window.location='<?php echo url_for('long_term_program/delete_condition') ?>?id='+$(this).attr('db_id');
                });
            }
		
            function remove_button(){
                $('.sf_admin_form_row button').remove();
            }
		
            function add_condition(){
                remove_button();
                _html = $('.sf_admin_form_field_condition_1 > div').html();
                _new_html = str_replace('condition_1','condition_'+index,_html);
                _new_html = str_replace('condition 1','condition '+index,_new_html);
                $('.sf_admin_form_row:last').append( '<div>'+_new_html+'</div>' );
                $('.sf_admin_form_row:last input[id*=condition_'+index+']').attr('value','');
                $('.sf_admin_form_row:last textarea[id*=condition_'+index+']').attr('value','');
                add_button();
                return false;
            }
		
		
            function str_replace (search, replace, subject, count) {
                j = 0,
                temp = '',
                repl = '',
                sl = 0,        fl = 0,
                f = [].concat(search),
                r = [].concat(replace),
                s = subject,
                ra = Object.prototype.toString.call(r) === '[object Array]',        sa = Object.prototype.toString.call(s) === '[object Array]';
                s = [].concat(s);
                if (count) {
                    this.window[count] = 0;
                } 
                for (i = 0, sl = s.length; i < sl; i++) {
                    if (s[i] === '') {
                        continue;
                    }        for (j = 0, fl = f.length; j < fl; j++) {
                        temp = s[i] + '';
                        repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
                        s[i] = (temp).split(f[j]).join(repl);
                        if (count && s[i] !== temp) {                this.window[count] += (temp.length - s[i].length) / f[j].length;
                        }
                    }
                }
                return sa ? s : s[0];
            }
        </script>
    </head>
    <body>
        <div class="container">
            <div class="header"><?php echo image_tag('header.jpg') ?></div>
            <?php include_component('sfAdminDash', 'header'); ?>
            <div class="cus_admin_content"><?php echo $sf_content ?></div>
            <?php include_partial('sfAdminDash/footer'); ?>
        </div>
    </body>
</html>
